var gulp = require('gulp'),
  autoprefixer = require('gulp-autoprefixer'),
  stylus = require('gulp-stylus'),
  cssmin = require('gulp-minify-css'),
  imagemin = require('gulp-imagemin'),
  less = require('gulp-less');

var browserSync = require('browser-sync').create();
var reload = browserSync.reload;

//创建静态服务器并监听less文件和html文件的修改
gulp.task('serve', ['cssFix'], function() {

  browserSync.init({
    server: "./",
  });

  gulp.watch("src/less/*.less", ['cssFix']);
  gulp.watch("./*.html").on('change', reload);
});

//编译less 自动增加后缀 css压缩

gulp.task('cssFix', function() {
  gulp.src('src/less/*.less')
    .pipe(
      less()
    )
    .pipe(autoprefixer({
      browsers: ['last 2 versions', 'Android >= 4.0'],
      cascade: true, //是否美化属性值 默认：true 像这样：
      remove: false //是否去掉不必要的前缀 默认：true
    }))
    // .pipe(cssmin({
    //   keepSpecialComments: '*'
    // }))
    .pipe(gulp.dest('src/css'))
    .pipe(reload({
      stream: true
    }));
});

//图片压缩
// gulp.task('Imagemin', function() {
//   gulp.src('src/img/*.{png,jpg,gif,ico}')
//     .pipe(imagemin())
//     .pipe(gulp.dest('dist/img'));
// });

gulp.task('default', ['serve']);
